import request from '@/utils/request'

export function login(data) {
  console.log(data)
  return request({
    url: '/user/login',
    method: 'post',
    // data
    params: { username: data.username, password: data.password, usertype: data.usertype }
  })
}

// export function getInfo(token) {
//   return request({
//     url: '/vue-element-admin/user/info',
//     method: 'get',
//     params: { token }
//   })
// }
//
// export function logout() {
//   return request({
//     url: '/vue-element-admin/user/logout',
//     method: 'post'
//   })
// }
export function changePassword(data) {
  return request({
    url: '/user/changePassword',
    method: 'post',
    params: { username: data.username, oldPassword: data.oldPassword, newPassword: data.newPassword }
  })
}

export function register(data) {
  console.log(data)
  return request({
    url: '/user/register',
    method: 'post',
    params: { newUsername: data.newUsername, newPassword: data.newPassword, usertype: data.usertype }
  })
}

export function getInfo(token) {
  return request({
    url: '/user/info',
    method: 'get',
    params: { token }
  })
}

export function logout() {
  return request({
    url: '/user/logout',
    method: 'post'
  })
}

export function getModelInfo() {
  return request({
    url: '/info/model',
    method: 'get'
  })
}

export function getDatasetInfo() {
  return request({
    url: '/info/dataset',
    method: 'get'
  })
}

export function getFile(fileName) {
  return request({
    url: '/get',
    method: 'get',
    params: { filename: fileName }
  })
}

export function getImg(fileName) {
  return request({
    url: '/get',
    method: 'get',
    responseType: 'blob',
    params: { filename: fileName }
  })
}

export function train(data) {
  console.log(data)
  return request({
    url: '/train',
    method: 'post',
    params: { lr: data.lr, epoch: data.epoch, train_path: 'dataset/train.txt' }
  })
}

